<div id="main">
    <div id="contents">
        <form method="post" action="#" name="filters" id="form1">
            <fieldset>
                <legend>
                    <label sid="virtual.virtual_server"></label>
                </legend>
                <div class="frame_tab_layer">
                    <table class="cmenutitle" cellspacing="0" cellpadding="0" border="0" width="100%">
                        <tbody>
                        <tr>
                            <td class="frame_tab_left">
                                <label for="singlePortVirtualSrvIPAddr">
                                    <label sid="forwards.virtual_server_ipaddr"></label>
                                </label>
                            </td>
                            <td class="frame_tab_right">
                                <input id="s_ipAddr" type="text" name="s_ipAddr" size="16">
                                <span class="x-form-tip" id="s_ipAddrTip"></span>

                            </td>
                        </tr>
                        <tr>
                            <td class="frame_tab_left">
                                <label for="singlePortVirtualSrvPublicPort">
                                    <label sid="virtual.public_port"></label>
                                </label>
                            </td>
                            <td class="frame_tab_right">
                                <input id="s_publicPort" type="text" name="s_publicPort" size="5">
                            </td>
                        </tr>
                        <tr>
                            <td class="frame_tab_left">
                                <label for="singlePortVirtualSrvPrivatePort">
                                    <label sid="virtual.private_port"></label>
                                </label>
                            </td>
                            <td class="frame_tab_right">
                                <input id="s_privatePort" type="text" name="s_privatePort" size="5">
                            </td>
                        </tr>
                        <tr>
                            <td class="frame_tab_left">
                                <label for="singlePortVirtualSrvProtocol">
                                    <label sid="firewall.protocol"></label>
                                </label>
                            </td>
                            <td class="frame_tab_right">
                                <select id="s_protocol" name="s_protocol">
                                    <option value="3" select="">TCP&amp;UDP</option>
                                    <option value="1">TCP</option>
                                    <option value="2">UDP</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td class="frame_tab_left">
                                <label for="singlePortVirtualSrvComment">
                                    <label sid="firewall.comment"></label>
                                </label>
                            </td>
                            <td class="frame_tab_right">
                                <input id="s_comment" type="text" maxlength="32" size="16" name="s_comment">
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2"></td>
                        </tr>
                        <tr>
                            <td class="frame_tab_center" colspan="2">
                                <input id="save_button_2" class="button" type="button" name="save_button_2" sid="sbutton.add">
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </fieldset>
            <fieldset>
                <legend>
                    <label sid="virtual.virtual_server_list"></label>
                </legend>
                <div class="frame_tab_layer">
                    <table id="porttable_2" class="cmenutitle" cellspacing="0" cellpadding="0" border="0" width="100%"> </table>
                </div>
            </fieldset>
        </form>
    </div>
</div>
<br>
<div id="helpContainer">
    <div id="help">
        <div>
            <h2>
                <label sid="share.help"></label>
            </h2>
        </div>
        <div id="helpBody">
        <dl>
            <dt class="term">
                <label sid="virtual.virtual_server"></label>
            </dt>
            <dd class="definition">
                <label sid="ports.comment"></label>
            </dd>
        </dl>
    </div>
    </div>
</div>
<script type="text/javascript" src="js/libTable.js"></script>
<script type="text/javascript">

    var virtual_data_2 = new Array();
    var old_virtual_2=0;
    load_html();

    $.formValidator.initConfig({debug:false,submitOnce:true,submitButtonID:"save_button_2",
        onError:function(msg, obj, errorlist) {

        },
        onSuccess:function(){
            var ipAddr = $("#s_ipAddr").val();
            var publicPort = $("#s_publicPort").val();
            var privatePort = $("#s_privatePort").val();
            var protocol = $("#s_protocol").val();
            var comment=$("#s_comment").val();
            if($("#save_button_2").val()==sbutton.modify){
                virtual_data_2[old_virtual_2][0]=ipAddr;
                virtual_data_2[old_virtual_2][1]=publicPort;
                virtual_data_2[old_virtual_2][2]=privatePort;
                virtual_data_2[old_virtual_2][3]=protocol;
                virtual_data_2[old_virtual_2][4]=comment;
            }else{
                var newarray = new Array();
                newarray[0]=ipAddr;
                newarray[1]=publicPort;
                newarray[2]=privatePort;
                newarray[3]=protocol;
                newarray[4]=comment;
                virtual_data_2.push(newarray);
                $("#save_button_2").val(sbutton.add);
            }
            var resultStr = JSONTostr(virtual_data_2);
            var settext='&id2329='+resultStr;
            submitform(modules["set_data"],settext,"port_forward_main_load");
            load_html();
        }
    });
    $("#s_ipAddr").formValidator({
        onFocus:errmsg.Info9
    }).regexValidator({
                regExp:regexEnum.notempty,
                onError:errmsg.Info3
            }).regexValidator({
                regExp:regexEnum.ip4,
                onError:errmsg.Info1
            });


    $("[name=submit_2]").click(function () {
        $(".errormsg").html('');
        var settext="";
        if($("#id2328_1").attr("checked")){
            settext+="&id2328="+$("#id2328_1").val();
        }
        if($("#id2328_2").attr("checked")){
            settext+="&id2328="+$("#id2328_2").val();
        }
        submitform(modules["set_data"],settext,"port_forward_main_load");
    });


	
function load_html(){
	var sendtext = '&id=2329';
	DataRequest("get_json",sendtext,function(data){
		//updatecfgvalue("id2328",data["id2328"]);
		var tmparray_2 = strToJSON(data["id2329"]);
		//if(tmparray_2!=""&&tmparray_2){
			virtual_data_2 = tmparray_2;
			virtual_paint_list_2(tmparray_2);
		//}
	});
}

function virtual_paint_list_2(data){
 var data_new=new Array();
 var j=0;
  for(var i=0;i<data.length;i++){
 	var ID = parseInt(parseInt(i)+1);
  	var ipaddr = replacestr(data[i][0]);
  	var publicPort = replacestr(data[i][1]);
 	var privatePort = replacestr(data[i][2]);
 	var comment = replacestr(data[i][4]);
 if(data[i][3]=="1"){
  	var protocol = "TCP";
  }else if(data[i][3]=="2"){
  	var protocol = "UDP";
  }else if(data[i][3]=="3"){
  	var protocol = "TCP&UDP";
  }else{
  	var protocol = "";
  	}
  data_new.push({ID:ID,ipaddr:ipaddr,publicPort:publicPort,privatePort:privatePort,protocol:protocol,comment:comment});
  j = i;
 }
 var fun_arr = [{type:"modify",name:"virtual_change_2"},{type:"del",name:"virtual_del_2"}];
 var tab = new libTable(new Array(firewall.no,forwards.virtual_server_ipaddr,virtual.public_port,virtual.private_port,firewall.protocol,firewall.comment,msg.op),data_new,1,10);
 print_table("porttable_2",tab,fun_arr, true);
}

function virtual_change_2(id,ipaddr,publicPort,privatePort,protocol,comment)
{
 obj = virtual_data_2[parseInt(id)-1];
 old_virtual_2 = parseInt(id)-1;
 with(obj){
  $("#s_ipAddr").val(ipaddr);
  $("#s_publicPort").val(publicPort);
  $("#s_privatePort").val(privatePort);
  $("#s_comment").val(comment);
	if(protocol == "TCP"){
 	 listselect("s_protocol","1");
  }else if(protocol == "UDP"){
 	 listselect("s_protocol","2");
  }else if(protocol == "TCP&UDP"){
 	 listselect("s_protocol","3");
  }
 }
 $("#save_button_2").val(sbutton.modify);
}




function virtual_del_2(id,ipaddr,publicPort,privatePort,protocol,comment){
 if(confirm(msg.confirm_del)){
// show_message("del",msg.deleting);
 virtual_data_2[parseInt(id)-1] = [];
 var resultStr = JSONTostr(virtual_data_2);
  var settext='&id2329='+resultStr;
  submitform(modules["set_data"],settext,"port_forward_main_load");
  load_html();
 }
}
</script>

